﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo.Grid
{
    public partial class Controls_Grid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void gridPanel_LoadPageData(object sender, ExtJSExtender.Controls.LoadPageDataEventArgs e)
        {
            var dataStore = e.DataStore;
            try
            {
                PetaPoco.Sql sql = PetaPoco.Sql.Builder.Append("select 物料ID,物料名称,物料编码,物料分类ID from 基础_物料");
                sql.OrderBy("物料编码");

                Demo.Data.MatrixData data = new Data.MatrixData("datuhe");
                Demo.Data.MatrixDataPage pageData = data.FetchPageDataTable(e.CurrentPage, e.PageSize, sql);

                dataStore.TotalCount = (int)pageData.TotalItems;
                dataStore.BindData(pageData.Data);
            }
            catch
            {
                dataStore.TotalCount = 1024;
                dataStore.Data = new List<Dictionary<string, object>>();
                var dic = new Dictionary<string, object>();
                dic.Add("物料ID", "1");
                dic.Add("物料名称", "桌子");
                dic.Add("物料编码", "0001");
                dic.Add("物料分类ID", "00");
                dataStore.Data.Add(dic);
                dic = new Dictionary<string, object>();
                dic.Add("物料ID", "2");
                dic.Add("物料名称", "椅子");
                dic.Add("物料编码", "0002");
                dic.Add("物料分类ID", "00");
                dataStore.Data.Add(dic);
                dic = new Dictionary<string, object>();
                dic.Add("物料ID", "3");
                dic.Add("物料名称", "拖把");
                dic.Add("物料编码", "0003");
                dic.Add("物料分类ID", "00");
                dataStore.Data.Add(dic);
            }
        }
    }
}